package com.mes.md.controller;

import com.mes.common.pojo.MESResult;
import com.mes.pojo.md.ItemType;
import com.mes.md.service.ItemTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author hitsune
 * @Company kafu chino
 * @Description
 * @Time 2024/10/16 19:22
 */

@RestController
@RequestMapping("/itemtype")
@CrossOrigin
public class ItemTypeController {

    @Autowired
    private ItemTypeService itemTypeService;

    @GetMapping("/getList")
    public MESResult selectItemTypeList(ItemType itemType){
        List<ItemType> list = itemTypeService.selectItemTypeList(itemType);
        return MESResult.success(list);
    }

    @GetMapping("/getListById")
    public MESResult selectItemTypeById(ItemType itemType){
        List<ItemType> list = itemTypeService.selectItemTypeById(itemType);
        return MESResult.success(list);
    }

    @PostMapping("/save")
    public MESResult insertItemType(@RequestBody ItemType itemType){
        itemTypeService.insertItemType(itemType);
        return MESResult.success();
    }

    @DeleteMapping("/del")
    public MESResult deleteItemType(Long itemTypeId){
        itemTypeService.deleteItemType(itemTypeId);
        return MESResult.success();
    }

    @PostMapping("/update")
    public MESResult updateItemType(@RequestBody ItemType itemType){
        itemTypeService.updateItemType(itemType);
        return MESResult.success();
    }

    @GetMapping("/isParent")
    public MESResult itemTypeIsParent(Long itemTypeId){
        Integer num = itemTypeService.itemTypeIsParent(itemTypeId);
        return MESResult.success(num);
    }
}
